<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<div class="login" style="border: black">
    <form>
        <table align="center" style="margin-top: 20%;max-width: 15%">
            <tr>
                <td><span>邮箱</span></td>
                <td><input type="text" id="email" name="email"></td>
            </tr>
            <tr>
                <td><span>密码</span></td>
                <td><input type="password" id="password" name="password"></td>
            </tr>
            <tr>
                <td colspan="2"></td>
            </tr>
            <tr bgcolor="green" id="login">
                <td colspan="2" align="center">
                    <label style="color: white">登&nbsp;&nbsp;录</label>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <span id="message" style="color:red"></span>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <a style="color: green; text-decoration:none;" href="register.html">注册新账号</a>
                </td>
            </tr>
        </table>
    </form>
</div>

</body>

<script src="jquery-1.9.1.min.js"></script>
<script>
    $(function () {
        login.init();
    });
    let login = {
        init: function () {
            $('#login').click(function () {
                login.login();
            });
        },

        login:function () {
            $.ajax({
                url: '/api/user/login',
                type:'post',
                dataType:'json',
                data:{
                    'email':$('#email').val(),
                    'password':$('#password').val()
                },
                success:function(data) {
                    if (data.code == 200) {
                        alert('登录成功')
                        window.location='/static/welcome.html'
                    } else {
                        $('#message').text(data.message);
                    }
                }
            });
        }
    };
</script>
</html>